// pages/addorder/addorder.js
var Http = require('../../utils/http');
var Utils = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    submitLoading: false,
    ajaxStatus: '',
    ajaxInfo: '',
    items: [
      { name: '电话', value: '1',  checked: 'true' },
      { name: '短信/微信/其他', value: '2' }
    ],
    courseSelect: [
      // { pt_order_id: '111', course_name: '电话' }
    ],
    followDate: '',
    followTime: '',
    formData: {
      pt_id: '', // 教练id
      content_way: '1', // 1 电话 2短信/微信 3其他
      remarks1: '', // 联系目的
      remarks: '', //内容备
      follow_time: '', // 跟进时间 格式必须是 yyyy-mm-dd
      pt_order_id: '', // 	私教课订单id
      member_id: '', // 会员id
      shop_id: '' // 门店id
    }
  },
  radioChange(e) {
    this.setData({
      'formData.content_way': e.detail.value
    })
  },
  remarkInput(e) {
    this.setData({
      'formData.remarks': e.detail.value
    })
  },
  contactTargetInput(e) {
    this.setData({
      'formData.remarks1': e.detail.value
    })
  },
  followDateChange(e) {
    this.setData({
      'followDate': e.detail.value,
      'formData.follow_time': e.detail.value + ' ' + this.data.followTime
    });
  },
  followTimeChange(e) {
    this.setData({
      'followTime': e.detail.value,
      'formData.follow_time': this.data.followDate + ' ' + e.detail.value
    });
  },
  submitOrder() {
    const self = this;
    if (this.data.followDate.length === 0 || this.data.followTime.length === 0) {
      self.setData({
        'ajaxStatus': 'warning',
        'ajaxInfo': '请选择跟进日期和时间'
      });
      return false;
    }
    if (this.data.formData.remarks1.length === 0) {
      self.setData({
        'ajaxStatus': 'warning',
        'ajaxInfo': '请输入跟进目的'
      });
      return false;
    }
    this.setData({
      'submitLoading': true
    });
    Http.post('/AddFollowUpPost', this.data.formData, (res) => {
      this.setData({
        'submitLoading': false
      });
      if (res.flag) {
        self.setData({
          'ajaxStatus': 'success',
          'ajaxInfo': res.msg
        });
        setTimeout(()=> {
          wx.navigateBack({
            delta: 2
          })
        }, 2000);
      } else {
        self.setData({
          'ajaxStatus': 'error',
          'ajaxInfo': res.msg
        })
      }
    }, () => {
      this.setData({
        'submitLoading': true
      });
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      'formData.member_id': options.memberid,
      'formData.pt_order_id': options.orderId,
      'followDate': Utils.dateFormat(new Date(), 'yyyy-MM-dd')
    });
    const self = this;
    Http.getLoginInfo((loginInfo) => {
      this.setData({
        'formData.pt_id': loginInfo.pt_id,
        'formData.shop_id': loginInfo.shop_id
      });
      // Http.post('/MemberCourseList', {
      //   pt_id: loginInfo.pt_id,
      //   shop_id: loginInfo.shop_id,
      //   member_id: options.memberid
      // }, (res) => {
      //   if (res.flag) {
      //     self.setData({
      //       'courseSelect': res.data
      //     })
      //   }
      // });
    });
  }
})
